package com.smart.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.smart.model.domain.OperateRolePermissionDO;
import com.smart.model.request.OperateRolePermissionRequest;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author zhanghong
 */
@Repository
public interface OperateRolePermissionMapper extends BaseMapper<OperateRolePermissionDO> {
    OperateRolePermissionDO selectDOById(Long id);
    List<OperateRolePermissionDO> selectDOList(OperateRolePermissionDO operateRolePermission);
    int insertDO(OperateRolePermissionDO operateRolePermission);
    int batchDO(List<OperateRolePermissionDO> operateRolePermissionDOList);
    int updateDO(OperateRolePermissionDO operateRolePermission);
    int deleteDOById(Long id);
    int deleteDOByIds(String[] ids);

    @Select({"<script>",
            "   select count(1) from operate_role_permission",
            "   <where>",
            "       deleted=0",
            "       <if test=\"1==0\">and id=#{param.id}</if>",
            "   </where>",
            "</script>"})
    long pageCount(@Param("param") OperateRolePermissionRequest param);
    @Select({"<script>",
            "   select * from operate_role_permission",
            "   <where>",
            "       deleted=0",
            "       <if test=\"1==0\">and id=#{param.id}</if>",
            "   </where>",
            "   order by create_time desc limit #{limit} offset #{offset}",
            "</script>"})
    List<OperateRolePermissionDO> pageQuery(@Param("param") OperateRolePermissionRequest param, @Param("limit") int limit, @Param("offset") long offset);

    @Delete("delete from operate_role_permission where role_id = #{roleId}")
    void deleteByRoleId(long roleId);
}
